﻿// =================================================================== 
// 业务逻辑层(GDIT.BLL)
//====================================================================
// 文件：BRoles.cs
// 项目名称：学院网站
// 创建时间：2012-08-12
// 负责人：ChenZhiGang
//引用DevExpress.Data.Filtering，DevExpress.Xpo程序集
// 程序集介绍：用户角色操作逻辑
// ===================================================================
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using GDIT.Base.LogHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDIT.Model;

namespace GDIT.BLL
{
    public class BRoles
    {
        private Pattern.DALAbstractFactory dataFactory = DataProvider.defaultProvider;

        /// <summary>
        /// 新增角色
        /// </summary>
        /// <param name="detailMenu">需要新增的角色对象</param>
        /// <returns>1：新增成功 2：新增失败</returns>
        public bool InsertRoles(Mtb_Roles roles)
        {
            Logger.Info(String.Format("角色对象名字[{0}]", roles.RoleName));
            int result = dataFactory.DALRolesProvider.InsertRoles(roles);
            if (result == 1)
            {
                Logger.Info("Insert success");
                return true;
            }
            else
            {
                Logger.Info("Insert false");
                return false;
            }
        }

        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="roles"></param>
        /// <returns></returns>
        public bool InsertUserToRoles(string userName,Mtb_Roles roles)
        {
            Logger.Info(String.Format("角色对象名字[{0}],新增用户的对象[{1}]", roles.RoleName,userName));
            int result = dataFactory.DALRolesProvider.InsertUserToRoles(roles);
            if (result == 1)
            {
                Logger.Info("Insert success");
                return true;
            }
            else
            {
                Logger.Info("Insert false");
                return false;
            }
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="detailMenu">需要删除的角色对象</param>
        /// <returns>1：删除成功 0：删除失败</returns>
        public bool DeleteRoles(Mtb_Roles roles)
        {
            Logger.Info(String.Format("角色对象名字[{0}]", roles.RoleName));
            int result = dataFactory.DALRolesProvider.DeleteRoles(roles);
            if (result == 1)
            {
                Logger.Info("Delete success");
                return true;
            }
            else
            {
                Logger.Info("Delete false");
                return false;
            }
        }

        /// <summary>
        /// 更新角色
        /// </summary>
        /// <param name="detailMenu">需要更新的角色对象</param>
        /// <returns>1：更新成功 0：更新失败</returns>
        public bool UpdateRoles(Mtb_Roles roles)
        {
            Logger.Info(String.Format("角色对象名字[{0}]", roles.RoleName));
            int result = dataFactory.DALRolesProvider.UpdateRoles(roles);
            if (result == 1)
            {
                Logger.Info("Update success");
                return true;
            }
            else
            {
                Logger.Info("Update false");
                return false;
            }
        }

        /// <summary>
        /// 查询所有的角色列表
        /// </summary>
        /// <returns>所有的角色列表</returns>
        public XPCollection SelectRoles()
        {
            return dataFactory.DALRolesProvider.SelectRoles();
        }

        /// <summary>
        /// 查询单一的角色对象
        /// </summary>
        /// <returns>单一的角色对象</returns>
        public Mtb_Roles SelectRolesByRoles(Mtb_Roles roles)
        {
            return dataFactory.DALRolesProvider.SelectRolesByRoles(roles);
        }
    }
}
